﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using IPTV.module;
using System.Text;
using System.IO;
using System.Threading;
using IPTV.service;
using Microsoft.TV.TVControls;

namespace IPTV.util
{
    public class CommonUtil
    {

        static object locker = new object();

        public const string VISITRE_RECORD_ID_TYPE_VIDEO = "video";
        public const string VISITRE_RECORD_ID_TYPE_ZT = "zt";
        public const string VISITRE_RECORD_ID_TYPE_VIDEOSOURCE = "videosource";
        public const string VISITRE_RECORD_ID_TYPE_LOGIN = "login";
        public const string SESSION_GRADE_ID = "gradeId";
        public const string SESSION_SUBJECT_ID = "subjectId";
        public const string NO_IMAGE_FOUND = "找不到图片";
        public const string NO_DATA_FOUND = "当前选项没有数据";
        public const int MAX_LINE_LENGTH = 16;
        public const int MAX_TITLE_LENGTH = 18;
        public const string SPLITOR = ";";
        public const string PRIMARY_PLATE_KIND = "XXKTQJ";
        public static int PAY_ACCOUNT = 1;
        public static int FREE_ACCOUNT = 0;
        public static string LOGIN = "login";
        public static string ZT = "zt";
        public static string ZSD = "zsd";
        public static string SESSION_USER = "user";

        public CommonUtil()
        {

        }

        public enum ImageSizeType : uint
        {
            PicOne = 1,
            PicTwo = 2,
            Small = 3
        }   

        public static void startVisitRecordLogThread(VisitRecordDto visitRecord)
        {

            Thread t = new Thread(delegate()
            {
                lock (locker)
                {
                    
                    CommonService cs = new CommonService();
                    cs.addVisitRecord(visitRecord);
                }
            });
            t.Start();
        }

        public static TVVerticalFlowPanel getNoDataTVVerticalFlowPanel(String id, bool isVisible)
        {
            TVVerticalFlowPanel tfp = new TVVerticalFlowPanel();
            tfp.ID = id;
            tfp.IsVisible = isVisible;
            tfp.Top = 120;
            tfp.Left = 54;
            tfp.Height = 307;
            tfp.Width = 759;

            TVLabel noDataLabel = new TVLabel();
            noDataLabel.Text = NO_DATA_FOUND;
            noDataLabel.Height = 300;
            noDataLabel.Width = 700;
            noDataLabel.FontStyle = "Reg24";
            System.Drawing.Color c = System.Drawing.Color.FromArgb(13, 70, 1);
            noDataLabel.Foreground = new TVColor(c);
            //noDataLabel.Background = new FillSpec(System.Drawing.Color.FromArgb(255, 0, 0));
            tfp.Controls.Add(noDataLabel);

            return tfp;
        }

        
        public static string subEllipsisText(string valueStr,int subLength)
        {
            if (valueStr.Length > subLength)
            {
                valueStr = valueStr.Substring(0, subLength) + "...";
            }
            return valueStr;
        }

        public static string replaceLineText(string valueStr)
        {
            if (null != valueStr)
            {
                string tmp = valueStr.Replace("\r\n", "");
                return tmp.Replace(" ", "");
            }
            else
            {
                return "";
            }
        }
        

    }

   
}